﻿using System.Collections.Generic;

namespace Mefisto.Core.Caching.Contracts
{
    public interface ICacheProvider
    {
        /// <summary>
        /// Method for getting a cache element
        /// </summary>
        /// <typeparam name="TValue">Cache element type</typeparam>
        /// <param name="value">Value stored in cache</param>
        /// <param name="cacheRegion">Region of the cache (Optional)</param>
        /// <param name="cacheKeyParts">Named parameters making the cache element unique</param>
        /// <returns>True if an element was stored in cache, else False</returns>
        bool Get<TValue>(out TValue value, string cacheRegion = "", params string[] cacheKeyParts);

        /// <summary>
        /// Get all cached elements
        /// </summary>
        /// <param name="cacheRegion">Region of the cache (Optional)</param>
        /// <returns>List of cached elements</returns>
        IEnumerable<KeyValuePair<string, object>> GetAll(string cacheRegion = "");

        /// <summary>
        /// Store an element in cache
        /// </summary>
        /// <typeparam name="TValue">Cache element type</typeparam>
        /// <param name="value">Elément à mettre en cache</param>
        /// <param name="cacheRegion">Region of the cache (Optional)</param>
        /// <param name="cacheKeyParts">Named parameters making the cache element unique</param>
        void Set<TValue>(TValue value, string cacheRegion = "", params string[] cacheKeyParts);

        /// <summary>
        /// Store an element in cache, with a time retention
        /// </summary>
        /// <typeparam name="TValue">Cache element type</typeparam>
        /// <param name="cacheRegion">Region of the cache</param>
        /// <param name="value">Clé associée à cet élément</param>
        /// <param name="duration">Durée du cache en minutes</param>
        /// <param name="cacheKeyParts">Named parameters making the cache element unique</param>
        void Set<TValue>(TValue value, int duration, string cacheRegion = "", params string[] cacheKeyParts);

        /// <summary>
        /// Supprime un élément du cache
        /// </summary>
        /// <param name="cacheRegion">Region of the cache</param>
        /// <param name="cacheKeyParts">Named parameters making the cache element unique</param>
        void Remove(string cacheRegion = "", params string[] cacheKeyParts);

        /// <summary>
        /// Clear all cached elements
        /// </summary>
        /// <param name="cacheRegion">Region of the cache</param>
        void Clear(string cacheRegion = "");
    }
}